package com.atguigu.mapreduce.solution;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SolutionMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    private final Text userId = new Text();
    private final IntWritable amount = new IntWritable();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");
        userId.set(fields[1]);
        amount.set(Integer.parseInt(fields[2]));
        context.write(userId, amount);
    }
}
